package lac.serviceuint;

import lac.serviceuint.cfg.Logic;

public abstract class LogicBean {
	
	//private Logic logic;
	
	public Logic getLogic() {
		return getCurrentVar("$logic", Logic.class);
	}

	public void setLogic(Logic logic) {
		setCurrentVar("$logic",logic);
	}

	protected <T> T getCurrentVar(Enum<?> name,Class<T> type){
		/*return ServiceUnitContext.getCurrentVar(name.name(),type);*/
		return this.getCurrentVar(name.name(), type);
	}
	
	protected <T> T getCurrentVar(Enum<?> name,T type){
		//return ServiceUnitContext.varMapContext.get().get(name.name())==null?null:(T) ServiceUnitContext.varMapContext.get().get(name);
		return getCurrentVar(name.name(), type);
	}
	
	protected void setCurrentVar(Enum<?> name,Object value){
		//ServiceUnitContext.setCurrentVar(name,value);
		this.setCurrentVar(name.name(), value);
	}
	
	protected <T> T getCurrentVar(String name,Class<T> type){
		return ServiceUnitContext.getCurrentVar(name, type);
	}
	
	protected <T> T getCurrentVar(String name,T type){
		return ServiceUnitContext.varMapContext.get().get(name)==null?null:(T) ServiceUnitContext.varMapContext.get().get(name);
	}
	
	protected void setCurrentVar(String name,Object value){
		ServiceUnitContext.setCurrentVar(name, value);
	}
	
	/**
	 * 设置返回结果
	 * @param result
	 */
	protected void setResult(Object result){
		ServiceUnitContext.resultContext.set(result);
	}
	
	protected Object getResult(){
		return ServiceUnitContext.resultContext.get();
	}
	
	
	/**
	 * 是否返回
	 * @param isReturn
	 */
	protected void isReturn(boolean isReturn){
		ServiceUnitContext.logicHandlerControlSignalContext.get().setReturn(isReturn);
	}
	
	/**
	 * 调到制定Handler
	 * @param name
	 */
	protected void goToLogicHandler(String name){
		ServiceUnitContext.logicHandlerControlSignalContext.get().setGoToLogicHandlerName(name);
	}

	/**
	 * 执行逻辑
	 */
	public abstract void doLogic() throws Exception;
}
